//
//  XTEncrypt+MD5.m
//  XTEncryptKit
//
//  Created by Tong on 2017/6/8.
//  Copyright © 2017年 Tong. All rights reserved.
//

#import "XTEncrypt+MD5.h"

#import <CommonCrypto/CommonDigest.h>

@implementation XTEncrypt (MD5)


/**
 获取 MD5 加密后的数据
 
 @param sourceString 需要加密的数据
 @return 加密后的数据
 */
+ (NSString *)getMD5EncryptStringFromString:(NSString *)sourceString
{
    const char *cStr = [sourceString UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    CC_MD5(cStr, (CC_LONG)strlen(cStr), digest);
    
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [result appendFormat:@"%02X", digest[i]];
    }

    return result;
}

@end
